$(document).ready(function(){
    //getColorjson("../static_file/js/colors.json") ;
    //ZeroClipboard.config( { swfPath: "./ZeroClipboard.swf" } );
    //var client = new ZeroClipboard($(".color-block"));
    $("body").on("mouseenter mouseleave",".name-box",function() {//绑定鼠标进入事件
        $(this).parent().toggleClass("top-show-100") ;
        $("footer .canvas-1").toggleClass("top-white-10") ;
    });
    $("body").on("mouseenter mouseleave",".val-box",function() {//绑定鼠标进入事件
        $(this).parent().toggleClass("top-show-100") ;
        $("footer .canvas-2").toggleClass("top-black-10") ;
    });
    /*client.on( "copy", function (event) {
        var clipboard = event.clipboardData;
        clipboard.setData( "text/plain", "Copy me!" );
        alert('copy over!');
        // clipboard.setData( "text/html", "<b>Copy me!</b>" );
        // clipboard.setData( "application/rtf", "{\\rtf1\\ansi\n{\\b Copy me!}}" );
    });*/
    $("body").on('mouseenter mouseleave',".color-block-btn",function () {
        //$(this).siblings(".val-box").children("h2").toggleClass("cur-select") ;
        $(this).siblings(".color-display-val").toggleClass("cur-select")
    }) ;

});

function getColorjson(path) {
    $.ajax({
        url:path,
        type:"GET",
        dataType:"json",
        cache:true,
        success:function (data) {
            addColorBlock(data) ;
        },
        error:function () {
            alert("qwq") ;
        }
    }) ;
}
function addColorBlock(dataJson) {
    let res=dataJson ;
    $.each(res,function(index,obj){
        var tmp_rgb="rgba(" ;
        var tmp_rgb_show="" ;
        obj["RGB"].forEach(function (obj) {
            tmp_rgb+=obj.toString()+"," ;
            tmp_rgb_show+=obj.toString()+" " ;
        }) ;
        tmp_rgb+="1.0)"
        var tmp_color="<a class=\"color-block\" style=\"background:"
                +tmp_rgb+"\">"
                +"<div class=\"name-box\">"
                +"<h2>"+obj["name"]+"</h2>"
                +"</div>"
                +"<div class=\"val-box\">"
                +"<h2>"+tmp_rgb_show+"</h2>"
                +"</div>"
                +"<div class=\"color-display-val\">"
                +tmp_rgb
                +"</div>"
                +"<button class=\"color-block-btn\" data-clipboard-action=\"copy\" data-clipboard-target=\".cur-select\">"
                +"</button>"
                +"</a>"
        $(".all-box").append(tmp_color) ;
    }) ;
} ;
function displayProp(obj){    
    var names="";       
    for(var name in obj){       
       names+=name+": "+obj[name]+", ";  
    }  
    alert(names);  
}
function randomNum(minNum,maxNum){ 
    switch(arguments.length){ 
        case 1: 
            return parseInt(Math.random()*minNum+1,10); 
        break; 
        case 2: 
            return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 
        break; 
            default: 
                return 0; 
            break; 
    } 
} 